#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;

static long MAX = 1000000;
void solve()
{
    int tmp = 0;
    vector<int> v;
    for (int i = 0; tmp < MAX; i++)
    {
        if (i == 0)tmp = 0, v.push_back(0);
        else if (i == 1)tmp = 1, v.push_back(1);
        else
        {
            tmp = v[i - 1] + v[i - 2];
            v.push_back(tmp);
        };
    }
    int x;
    cin >> x;
    v.push_back(x);
    auto it = find(v.begin(), v.end(), x);
    int ret1 = abs(*(it + 1) - x);
    int ret2 = abs(*(it - 1) - x);
    cout << min(ret1, ret2);
}
int main() {
    solve();
    return 0;
}